<template>
  <a-modal
    title="查看详情"
    :width="1200"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleCancel"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-row style="width: 100%;">
          <a-col :span="24/2">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="日志ID">
              <a-input placeholder="请输入日志ID" v-decorator="['logId', {}]" :readOnly="!!model.id"/>
            </a-form-item>
          </a-col>
          <a-col :span="24/2">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="请求IP">
              <a-input placeholder="请输入请求的IP" v-decorator="['requestIp', {}]" :readOnly="!!model.id"/>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row style="width: 100%;">
          <a-col :span="24/2">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="请求URL">
              <a-input placeholder="请输入请求的URL" v-decorator="['requestUrl', {}]" :readOnly="!!model.id"/>
            </a-form-item>
          </a-col>
          <a-col :span="24/2">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="耗时(ms)">
              <a-input placeholder="请输入耗时(ms)" v-decorator="['timeConsuming', {}]" :readOnly="!!model.id"/>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row style="width: 100%;">
          <a-col :span="24/2">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="UserAgent">
              <a-textarea :rows="4" v-decorator="['clientName', {}]" :readOnly="!!model.id"/>
            </a-form-item>
          </a-col>
          <a-col :span="24/2">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="请求参数">
              <a-textarea :rows="4" v-decorator="['requestParam', {}]" :readOnly="!!model.id"/>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row style="width: 100%;">
          <a-col :span="24/2">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="接口内容">
              <a-textarea :rows="6" v-decorator="['responseText', {}]" :readOnly="!!model.id"/>
            </a-form-item>
          </a-col>
          <a-col :span="24/2">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="异常信息">
              <a-textarea :rows="6" v-decorator="['errorMsg', {}]" :readOnly="!!model.id"/>
            </a-form-item>
          </a-col>
        </a-row>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="接口类型">
          <a-radio-group  v-decorator="['logType',{}]" :disabled="!!model.id">
            <a-radio :value="72001">首页轮播图</a-radio>
            <a-radio :value="72002">首页导航</a-radio>
            <a-radio :value="72003">首页滚动新闻</a-radio>
            <a-radio :value="72004">刷新文案</a-radio>
            <a-radio :value="72012">微信登录</a-radio>
            <a-radio :value="72013">微信授权更新</a-radio>
            <a-radio :value="72014">虚拟换妆DIY</a-radio>
            <a-radio :value="72015">虚拟换妆</a-radio>
            <a-radio :value="72016">人脸融合DIY</a-radio>
            <a-radio :value="72017">人脸融合</a-radio>
            <a-radio :value="72018">痘斑痣检测</a-radio>
            <a-radio :value="72019">皮肤光滑度</a-radio>
            <a-radio :value="72020">肤色检测</a-radio>
            <a-radio :value="72021">皱纹检测</a-radio>
            <a-radio :value="72022">黑眼圈眼袋检测</a-radio>
            <a-radio :value="72023">垃圾分类检测</a-radio>
            <a-radio :value="72024">图片融合检测</a-radio>
            <a-radio :value="72025">图片背景色替换</a-radio>
            <a-radio :value="72026">手相分析</a-radio>
            <a-radio :value="72027">手相分析V2</a-radio>
            <a-radio :value="72028">图像违规检测</a-radio>
            <a-radio :value="72029">中草药检测</a-radio>
            <a-radio :value="72031">手相分析(线)</a-radio>
            <a-radio :value="72032">人脸变老</a-radio>
            <a-radio :value="72033">我的动物脸</a-radio>
            <a-radio :value="72034">性别反转</a-radio>
            <a-radio :value="72035">五官分析</a-radio>
            <a-radio :value="72036">累首天数</a-radio>
            <a-radio :value="72037">图片转字符画</a-radio>
            <a-radio :value="72038">图像识别</a-radio>
            <a-radio :value="72039">图像处理</a-radio>
            <a-radio :value="72040">人脸检测</a-radio>
            <a-radio :value="72041">手表识别</a-radio>
            <a-radio :value="72042">穿衣搭配</a-radio>
            <a-radio :value="72043">颜色识别</a-radio>
            <a-radio :value="72044">飞桨闲聊</a-radio>
            <a-radio :value="72045">小跟班机器人</a-radio>
            <a-radio :value="72046">街景动漫化</a-radio>
            <a-radio :value="72049">秃头模型</a-radio>
            <a-radio :value="72047">秃头海报</a-radio>
            <a-radio :value="72048">街景海报</a-radio>
            <a-radio :value="72050">圣诞模型</a-radio>
            <a-radio :value="72051">圣诞海报</a-radio>
            <a-radio :value="72052">小红花</a-radio>
          </a-radio-group>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {httpAction} from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "LiteApiLogModal",
    data() {
      return {
        title: "操作",
        visible: false,
        model: {},
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {},
        url: {
          add: "/log/liteApiLog/add",
          edit: "/log/liteApiLog/edit",
        },
      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({});
      },
      edit(record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'logId', 'clientName', 'requestIp', 'requestUrl', 'requestParam', 'responseText', 'logType', 'timeConsuming', 'errorMsg'))
          //时间格式化
        });

      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if (!this.model.id) {
              httpurl += this.url.add;
              method = 'post';
            } else {
              httpurl += this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化

            console.log(formData)
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel() {
        this.close()
      },
    }
  }
</script>

<style lang="less" scoped>

</style>